package com.yuan.web.servlet;

import com.yuan.service.AccountService;
import com.yuan.utlis.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/count")
public class ServletDemo01 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");
        String fromName = request.getParameter("from");
        String toName = request.getParameter("to");
        String money = request.getParameter("money");

        try {
            AccountService accountService = new AccountService();
            accountService.transfer(fromName,toName,Integer.parseInt(money));
            response.getWriter().write("转账成功!!!");
        } catch (Exception e) {
            e.printStackTrace();
            response.getWriter().write("转账失败！！");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
